package top.jasonlam.car.entity;


import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.CreationTimestamp;

import javax.persistence.*;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Null;
import java.util.Date;
import java.util.Set;

/**
 * replySet 级联操作  级联回复
 * Comment 评论
 * car 级联索引
 * content 评论内容
 * commentDate 评论日期
 * commentName 评论人
 *
 * @author jasonlam
 */
@Entity
@Table(name = "comment")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Comment {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    Long id;

    @Column(name = "car", nullable = false)
    @NotEmpty(message = "所属汽车发布单号不能为空")
    private String car;

    @Column(name = "content", nullable = false)
    @NotEmpty(message = "不能发布空评论")
    private String content;

    @Column(name = "commentdate", nullable = false)
    @CreationTimestamp
    private Date commentDate;

    @Column(name = "commentname", length = 20, nullable = false)
    @NotEmpty(message = "评论人账号不能为空")
    private String commentName;

    @OneToMany(targetEntity = Reply.class, cascade = {CascadeType.ALL}, mappedBy = "commentId")
    private Set<Reply> replySet;

}
